/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __DX_DXDRAWPRIMITIVE_H__
#define __DX_DXDRAWPRIMITIVE_H__

#pragma once

#include "DXResource.h"
#include "IDrawPrimitive.h"


namespace directx {

class Renderer;

struct VertexPNT {
	math::Vector3  position;
	math::Vector3  normal;
	math::Vector2f texcoord;
};

class DXDrawPrimitive :
	public IDrawPrimitive, 
	public DXResource
{
public:
	/// Creates a IDrawPrimitive of a box
	void createBox(float width, float height, float depth);

	/// Creates a IDrawPrimitive of a sphere
	void createSphere(float fRad, unsigned int slices, unsigned int stacks);

	/// Creates a IDrawPrimitive of a plane. 
	/// \todo Consider the normal to position the plane in space
	void createPlane(const math::Vector3 &normal, float d, const math::Vector2i &tesselation);

	/// Creates a IDrawPrimitive of a screen quad
	void createScreenQuad(int width, int height, int offsetX, int offsetY, float scaleFactor, const math::Vector4 &color);

	void createQuad(int width, int height, const math::Vector4 &color);

	/// Draws the primitive using DirectX
	void draw();

	/// Allow the renderer access to the protected members
	friend class Renderer;
	friend class IDrawPrimitive;

	virtual ~DXDrawPrimitive(void);
protected:
	DXDrawPrimitive(void);

	LPDIRECT3DVERTEXDECLARATION9 m_pVertexDecl;	///< The vertex declaration
	LPDIRECT3DVERTEXBUFFER9	     m_pFullBuffer;	///< The full vertex buffer
	LPD3DXMESH                   m_pMesh;		///< Stores the mesh data
};

} // namepsace

#endif
